<template>
  <el-dialog title="编辑开票详情" :visible.sync="dialogFormVisible" width="600px">
    <el-form
      ref="dataForm"
      :rules="rules"
      :model="temp"
      label-position="left"
      label-width="100px"
      style="margin: 0 30px"
    >
      <template>
        <el-form-item label="税号" prop="tax_no">
          <el-input v-model="temp.tax_no" placeholder="请输入税号" />
        </el-form-item>
        <el-form-item label="企业名称" prop="title">
          <el-input v-model="temp.title" placeholder="请输入企业名称" />
        </el-form-item>
        <!-- <el-form-item label="关联订单号">
          <p>{{ temp.related_orders.split(',') }}</p>
        </el-form-item> -->
        <el-form-item label="开户行帐号" prop="bank_account">
          <el-input v-model="temp.bank_account" placeholder="请输入开户行帐号" />
        </el-form-item>
        <el-form-item label="开户行地址" prop="bank_address">
          <el-input v-model="temp.bank_address" placeholder="请输入开户行地址" />
        </el-form-item>
        <el-form-item label="电子邮箱" prop="email">
          <el-input v-model="temp.email" placeholder="请输入电子邮箱" />
        </el-form-item>
        <el-form-item label="开票金额" prop="amount">
          <el-input v-model="temp.amount" placeholder="请输入开票金额" type="number" />
        </el-form-item>
        <el-form-item label="开票创建时间">
          <p>{{ temp.add_time }}</p>
        </el-form-item>
        <el-form-item label="开票状态">
          <el-tag :type="temp.status === 'invoiced' ? 'success' : 'info'"
            >{{ $invoiceStatus[temp.status] }}
          </el-tag>
        </el-form-item>
      </template>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取消</el-button>
      <el-button type="primary" @click="saveData">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { edit } from '@/api/invoices'
const rule = [{ required: true, message: '必填项不能为空' }]
export default {
  name: 'InvoiceEdit',

  data() {
    return {
      dialogFormVisible: false,
      id: '',
      temp: {
        tax_no: '',
        title: '',
        related_orders: [],
        bank_account: '',
        bank_address: '',
        email: '',
        add_time: '',
        status: ''
      },
      checkAll: false,
      isIndeterminate: true,
      rules: {
        name: rule,
        mobile: rule,
        password: rule,
        role_id: [{ required: true, message: '请选择用户角色', trigger: 'change' }],
        attraction_ids: [{ required: true, message: '请选择景区', trigger: 'change' }]
      },
      roleOptions: [],
      attractionOptions: []
    }
  },

  created() {},
  methods: {
    handleCreate() {
      this.id = ''
      this.temp = {
        name: '',
        mobile: '',
        password: '',
        role_id: '',
        attraction_ids: []
      }
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs.dataForm.clearValidate()
      })
    },
    // 编辑
    handleEdit(row) {
      this.id = row.id
      Object.assign(this.temp, row)
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs.dataForm.clearValidate()
      })
    },

    // 保存
    saveData() {
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          const d = JSON.parse(JSON.stringify(this.temp))
          console.log('d', d)
          edit(this.id, d).then(() => {
            this.$parent.fetchData()
            this.dialogFormVisible = false
            this.$parent.$notify({
              title: '成功',
              message: '修改成功',
              type: 'success'
            })
          })
        }
      })
    }
  }
}
</script>
<style scoped>
.item-p {
  margin: 0;
  /* height: 1px; */
}
</style>
